﻿using System;
using System.Data;
using DataAccess;

namespace Business
{
    public class BuTimeWeek
    {
        public static DataTable selRegisterWeek(string date, string email, string companyid)
        {
            DaTimeWeek timeWeek = new DaTimeWeek();


            DataTable data = timeWeek.selRegisterWeek(date, email, companyid);
            DataTable tmpTable = data.Clone();

            
            // Them cot bieu dien
            // Cot thu hai
            DataColumn column = new DataColumn();
            column = new DataColumn("MonH", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeMonH",typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeMonM", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("ComMon", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("IsFinishMon", typeof(String));
            tmpTable.Columns.Add(column);

            // Cot thu ba
            column = new DataColumn("TueH", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeTueH", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeTueM", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("ComTue", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("IsFinishTue", typeof(String));
            tmpTable.Columns.Add(column);

            // Cot thu tu
            column = new DataColumn("WedH", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeWedH", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeWedM", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("ComWed", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("IsFinishWed", typeof(String));
            tmpTable.Columns.Add(column);

            // Cot thu nam
            column = new DataColumn("ThuH", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeThuH", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeThuM", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("ComThu", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("IsFinishThu", typeof(String));
            tmpTable.Columns.Add(column);

            // Cot thu sau
            column = new DataColumn("FriH", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeFriH", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeFriM", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("ComFri", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("IsFinishFri", typeof(String));
            tmpTable.Columns.Add(column);

            // Cot thu bay
            column = new DataColumn("SatH", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeSatH", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeSatM", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("ComSat", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("IsFinishSat", typeof(String));
            tmpTable.Columns.Add(column);

            // Cot chu nhat
            column = new DataColumn("SunH", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeSunH", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("TimeSunM", typeof(Int32));
            tmpTable.Columns.Add(column);
            column = new DataColumn("ComSun", typeof(String));
            tmpTable.Columns.Add(column);
            column = new DataColumn("IsFinishSun", typeof(String));
            tmpTable.Columns.Add(column);
            foreach (DataRow row in data.Rows)
            {
                tmpTable.ImportRow(row);
            }
            // Do du lieu
            int numOfRow = tmpTable.Rows.Count;
            DataRow dtTmp;
            for (int i = 0; i < numOfRow; i++)
            {
                //tmpTable.ImportRow(data.Rows[i]);
                // Lay sid
                int sidMon = Int32.Parse(tmpTable.Rows[i]["SIDMon"].ToString());
                if (sidMon != 0)
                {
                    dtTmp = timeWeek.selRegisterWeekUti(sidMon, companyid).Rows[0];
                    tmpTable.Rows[i]["TimeMonH"] = dtTmp["SAReportTimeHour"];
                    tmpTable.Rows[i]["TimeMonM"] = dtTmp["SAReportTimeMinute"];
                    tmpTable.Rows[i]["ComMon"] = dtTmp["SADetails"];
                    string tmp = dtTmp["SADetails"].ToString();
                    tmpTable.Rows[i]["IsFinishMon"] = dtTmp["SAIsFinish"];
                    tmpTable.Rows[i]["MonH"] = dtTmp["SAReportTimeHour"].ToString() + ":" + dtTmp["SAReportTimeMinute"].ToString();
                }
            
                

                int sidTue = Int32.Parse(tmpTable.Rows[i]["SIDTue"].ToString());
                if (sidTue != 0)
                {
                    dtTmp = timeWeek.selRegisterWeekUti(sidTue, companyid).Rows[0];
                    tmpTable.Rows[i]["TimeTueH"] = dtTmp["SAReportTimeHour"];
                    tmpTable.Rows[i]["TimeTueM"] = dtTmp["SAReportTimeMinute"];
                    tmpTable.Rows[i]["ComTue"] = dtTmp["SADetails"];
                    tmpTable.Rows[i]["IsFinishTue"] = dtTmp["SAIsFinish"];
                    tmpTable.Rows[i]["TueH"] = dtTmp["SAReportTimeHour"].ToString() + ":" + dtTmp["SAReportTimeMinute"].ToString();
                }
                
            
                int sidWed = Int32.Parse(tmpTable.Rows[i]["SIDWed"].ToString());
                if (sidWed != 0)
                {
                    dtTmp = timeWeek.selRegisterWeekUti(sidWed, companyid).Rows[0];
                    tmpTable.Rows[i]["TimeWedH"] = dtTmp["SAReportTimeHour"];
                    tmpTable.Rows[i]["TimeWedM"] = dtTmp["SAReportTimeMinute"];
                    tmpTable.Rows[i]["ComWed"] = dtTmp["SADetails"];
                    tmpTable.Rows[i]["IsFinishWed"] = dtTmp["SAIsFinish"];
                    tmpTable.Rows[i]["WedH"] = dtTmp["SAReportTimeHour"].ToString() + ":" + dtTmp["SAReportTimeMinute"].ToString();
                }
                

                int sidThu = Int32.Parse(tmpTable.Rows[i]["SIDThu"].ToString());
                if (sidThu != 0)
                {
                    dtTmp = timeWeek.selRegisterWeekUti(sidThu, companyid).Rows[0];
                    tmpTable.Rows[i]["TimeThuH"] = dtTmp["SAReportTimeHour"];
                    tmpTable.Rows[i]["TimeThuM"] = dtTmp["SAReportTimeMinute"];
                    tmpTable.Rows[i]["ComThu"] = dtTmp["SADetails"];
                    tmpTable.Rows[i]["IsFinishThu"] = dtTmp["SAIsFinish"];
                    tmpTable.Rows[i]["ThuH"] = dtTmp["SAReportTimeHour"].ToString() + ":" + dtTmp["SAReportTimeMinute"].ToString();
                }
                
                int sidFri = Int32.Parse(tmpTable.Rows[i]["SIDFri"].ToString());
                if (sidFri != 0)
                {
                    dtTmp = timeWeek.selRegisterWeekUti(sidFri, companyid).Rows[0];
                    tmpTable.Rows[i]["TimeFriH"] = dtTmp["SAReportTimeHour"];
                    tmpTable.Rows[i]["TimeFriM"] = dtTmp["SAReportTimeMinute"];
                    tmpTable.Rows[i]["ComFri"] = dtTmp["SADetails"];
                    tmpTable.Rows[i]["IsFinishFri"] = dtTmp["SAIsFinish"];
                    tmpTable.Rows[i]["FriH"] = dtTmp["SAReportTimeHour"].ToString() + ":" + dtTmp["SAReportTimeMinute"].ToString();
                }
                

                int sidSat = Int32.Parse(tmpTable.Rows[i]["SIDSat"].ToString());
                if (sidSat != 0)
                {
                    dtTmp = timeWeek.selRegisterWeekUti(sidSat, companyid).Rows[0];
                    tmpTable.Rows[i]["TimeSatH"] = dtTmp["SAReportTimeHour"];
                    tmpTable.Rows[i]["TimeSatM"] = dtTmp["SAReportTimeMinute"];
                    tmpTable.Rows[i]["ComSat"] = dtTmp["SADetails"];
                    tmpTable.Rows[i]["IsFinishSat"] = dtTmp["SAIsFinish"];
                    tmpTable.Rows[i]["SatH"] = dtTmp["SAReportTimeHour"].ToString() + ":" + dtTmp["SAReportTimeMinute"].ToString();
                }
                

                int sidSun = Int32.Parse(tmpTable.Rows[i]["SIDSun"].ToString());
                if (sidSun != 0)
                {
                    dtTmp = timeWeek.selRegisterWeekUti(sidSun, companyid).Rows[0];
                    tmpTable.Rows[i]["TimeSunH"] = dtTmp["SAReportTimeHour"];
                    tmpTable.Rows[i]["TimeSunM"] = dtTmp["SAReportTimeMinute"];
                    tmpTable.Rows[i]["ComSun"] = dtTmp["SADetails"];
                    tmpTable.Rows[i]["IsFinishSun"] = dtTmp["SAIsFinish"];
                    tmpTable.Rows[i]["SunH"] = dtTmp["SAReportTimeHour"].ToString() + ":" + dtTmp["SAReportTimeMinute"].ToString();
                }
                
            }
            return tmpTable;
        }
    }
}
